package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Grade;
import cn.wolfcode.crm.domain.PotentialStudent;
import cn.wolfcode.crm.mapper.GradeMapper;
import cn.wolfcode.crm.mapper.PotentialStudentMapper;
import cn.wolfcode.crm.query.StudentShiftQueryObject;
import cn.wolfcode.crm.service.IStudentShiftService;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class StudentShiftServiceImpl implements IStudentShiftService {
    @Autowired
    private PotentialStudentMapper potentialStudentMapper;
    @Autowired
    private GradeMapper gradeMapper;


    @Override
    public PageResult queryShiftList(StudentShiftQueryObject qo) {
        int count = potentialStudentMapper.queryShiftCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<PotentialStudent> data = potentialStudentMapper.queryShift(qo);
        return new PageResult(count, data);
    }


    @Override
    public void update(PotentialStudent ps) {
        if (ps.getId() != null) {
            Grade grade = gradeMapper.selectByClassName(ps.getNewClassName());
            String s = String.valueOf(grade);
            ps.setNewClassName(s);
            potentialStudentMapper.updateByShift(ps);
        }
    }

    @Override
    public void audit(Long id) {
        PotentialStudent ps = potentialStudentMapper.selectByPrimaryKey(id);
        if (!ps.isShiftAudit()) {
//            Employee employee = UserContext.getUserContext();
            ps.setShiftAudit(true);
            potentialStudentMapper.audit(ps);
        }else {
            throw new RuntimeException("已经审核!!!!");
        }
    }




    @Override
    public void theAudit(long id) {
        PotentialStudent ps = potentialStudentMapper.selectByPrimaryKey(id);
//        potentialStudentMapper.setState(!ps.isState());
////        spending.setAuditMan(UserContext.getUserContext());
//        potentialStudentMapper.audit(ps);
    }


    @Override
    public List<PotentialStudent> All() {
        return potentialStudentMapper.selectAllByShift();
    }
}
